package com.tang.thread_test;

/**
 * @author tmh
 * @date 2024/3/28 20:18
 * @description
 */
public class wait_notify {
    public static void main(String[] args) throws InterruptedException {
        Object lock = new Object();
        // 创建线程并执行
        new Thread(() -> {
            System.out.println("线程1：开始执行");
            synchronized (lock) {
                try {
                    System.out.println("线程1：进入等待");
                    lock.wait();
                    System.out.println("线程1：继续执行");
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println("线程1：执行完成");
            }
        }).start();

        Thread.sleep(1000);
        synchronized (lock) {
            // 唤醒线程
            System.out.println("执行 notifyAll()");
            lock.notifyAll();
        }

    }
}
